define("pages/jls_cs/yqjrymain", [
        "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
        "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
        "../../plugins/artTemplate/artTemplate",
        "../../common/tools",
        "../../common/kss",
        "../../common/componts",
    ],
    function(require) {
        var comonts=require("../../common/componts");
        var kss=require("../../common/kss");
        var jbxxid="yqjryId";
        var selectid;
        var id;
        var Select = function(){
            comonts.initSelectPage(undefined);
            comonts.initSelect(undefined,undefined,undefined);
        }
        var tableInit=function(){
            comonts.initTable(jbxxid,{
                url:"/jls_jbxx/jbxxList",
                title:'',
                fit:true,
                tools:'#yqjryId',
                columns :  [
                    {
                        field: 'oid',
                        title: '',
                        formatter: function(value, rowData, rowIndex){
                            return '<input type="radio" name="ryRadio" id="ryRadio' + rowIndex + '" value="' + rowData.oid + '" />';
                        }},
                    {field : 'xm',title : '姓名',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(row.xm==null?"":row.xm)+'>'+(row.xm==null?"":row.xm)+'</span>'}},
                    {field : 'xb',title : '性别',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(row.xb==null?"":row.xb)+'>'+(row.xbString==null?"":row.xbString)+'</span>'}},
                    {field : 'csrq',title : '出生日期',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(row.csrq==null?"":row.csrq)+'>'+(row.csrq==null?"":row.csrq)+'</span>'}},
                    {field : 'rssj',title : '入所时间',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(row.rssj==null?"":row.rssj)+'>'+(row.rssj==null?"":row.rssj)+'</span>'}},
                    {field:'operate',title:'详细信息',align:'center',width : 60,
                        formatter:function(value, row, index){
                            var str = '<a href="#" data-target="#ckPhoto" value="'+index+'" name="opera" data-toggle="modal" class="easyui-linkbutton"><img src="../../img/xq.png"></a>';
                            return str;
                        }
                    }
                ] ,

                onLoadSuccess:function(data){
                    if(data.total>0){
                        $('#'+jbxxid).datagrid("selectRow", 0);
                        $("input[name='ryRadio']")[0].checked = true;
                    }
                    $("a[name='opera']").each(function(){
                        $(this).on('click',function () {
                            var index = $(this).attr('value');
                            var jbxx = data.rows[index];
                            kss.initJbxxxx(jbxx.gcbh,jbxx.rybh,jbxx.xm+"--详细信息");
                        });
                    });
                },

                //单击行选中取消事件
                onClickRow:function(rowIndex, rowData){
                    if(selectid!=rowData.id){
                        $("input[name='ryRadio']")[rowIndex].checked = true;
                        selectid=rowData.id;
                    }else{
                        $("#"+jbxxid).datagrid("unselectRow",rowIndex);
                        $("input[name='ryRadio']")[rowIndex].checked = false;
                        $('#'+jbxxid).datagrid('clearSelections');
                        selectid="";
                    }
                },
                onSelect:function(rowIndex, rowData){
                },
                rightmenu:function(){
                    //kss.initJbxxRightMenu(jbxxrightmenuid);
                },
            });
            //页面高度自适应
            $('#'+jbxxid).datagrid('resize',{
                height:($(window).height()-140),
            });
        }
        var findJbxx=function(){

            $('#'+jbxxid).datagrid('clearSelections');
            $('#'+jbxxid).datagrid('load',{
                'state':'R8',
            });
        }

        var addjydj=function(){
            //获得当前时间
            var d = new Date();
            var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
            xzry.show(jbxxid,{},refreshTable);
        }
        var jyrs=function(){
            //获得当前时间
            var d = new Date();
            var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
            jylr.show(jbxxid,{},refreshTable);
        }
        var bindAction=function(){

            $("#yqjry_query").on("click",function(){
                findJbxx();
            });
            $("#xzryrs").on("click",function () {
                var jbxx=$("#"+jbxxid).datagrid('getSelected');
                if(jbxx){
                    addjydj();
                }else{
                    $.messager.alert("提示","请选择要办理的人员!","info");
                }
            });

            $(window).keydown(function(event) {
                if (event.keyCode == 13) {
                    findJbxx();
                }
            });

        }
        var refreshTable=function(data){
            $('#'+jbxxId).datagrid('reload',{rybh:$('#'+jbxxId).datagrid('getSelected').rybh,"taskDefinitionKey":"kss_rsdj_zbsy","processDefinitionKey":"kss_rsdj"});
        }

        var initView=function(){
            tableInit();
            bindAction();
            Select();
        }
        initView();
    });
